// import nodata from '@/assets/images/Breed/no_data.png'
import nodataComponent from '@/plugins/NoData/NoData.vue'
import Vue from 'vue'

// 使用extend创建子类（构造函数）
const NoDataConstructor = Vue.extend(nodataComponent)

let load = false // 避免重复调用
// 实例化方法
const instance = new NoDataConstructor({
  el: document.createElement('div')
})

instance.show = false // 默认隐藏
// 创建方法
const nodata = {
  show (chartdom) {
    if (load || !chartdom) return
    load = true
    instance.show = true
    const dom = document.getElementById(chartdom)
    dom.after(instance.$el)
  },
  hide () {
    load = false
    instance.show = false
  }
}

export default {
  install () {
    if (!Vue.$nodata) {
      Vue.$nodata = nodata
    }
    Vue.mixin({
      created () {
        this.$nodata = Vue.$nodata
      }
    })
  }
}
